/**
 * 
 */
package xj.toolkit.fsm;

import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

/**
 * @author hp
 *
 */
public class DefaultStateRepository implements StateRepository {

	private Map<String, State> states = new HashMap<String, State>();
	
    /**
     * @param encoders the encoders to set
     */
    public void setStates(Collection<State> states) {
        this.states.clear();
        
        for ( State state : states) {
            this.states.put(FSMUtils.getStateNameOfInstance(state), state);
        }
    }
    
	public Collection<State> getStates() {
		return Collections.unmodifiableCollection( this.states.values() );
	}
	
	/* (non-Javadoc)
	 * @see com.skymobi.fsm.StateRepository#find(java.lang.String)
	 */
	public State find(String name) {
		return states.get(name);
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return "DefaultStateRepository [states=" + states.keySet() + "]";
	}

}
